package com.cam.framework.crud;

import com.cam.framework.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class CrudTreeDTO<DTO extends CrudTreeDTO<DTO>> extends CrudDTO {

    private static final long serialVersionUID = 1L;

    public CrudTreeDTO() {
    }

    public CrudTreeDTO(String id) {
        super(id);
    }

    private DTO parent;

    private String parentIds;

    private List<DTO> children = new ArrayList<>();

    /*
    * rootId
    * 一般用于表明实体类的默认根节点ID
    * 或者用于查询对应节点下的数据
    * */
    private String rootId;

    public void setRootId(String rootId) {
        this.rootId = rootId;
    }

    public String getRootId() {
        if (StringUtils.isEmpty(this.rootId)) return "0";
        return this.rootId;
    }

    public String getParentId() {
        if (this.parent != null) return this.parent.getId();
        return null;
    }

    public DTO getParent() {
        return parent;
    }

    public void setParent(DTO parent) {
        this.parent = parent;
    }

    public String getParentIds() {
        return parentIds;
    }

    public void setParentIds(String parentIds) {
        this.parentIds = parentIds;
    }

    public List<DTO> getChildren() {
        return children;
    }

    public void setChildren(List<DTO> children) {
        this.children = children;
    }
}
